package com.adlotto2.lcdns.cronos.parser;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import android.util.Log;

import com.adlotto2.lcdns.cronos.data.CNLottoAdListData;
import com.adlotto2.lcdns.cronos.datahandler.CNBaseDataParser;
import com.adlotto2.lcdns.cronos.datahandler.CNResultSet;

public class CNAdListParser extends CNBaseDataParser{
	protected void onParseContent(Element xmlObject, CNResultSet resultSet)
			throws Exception { // 수신 광고 리스트
		
		NodeList nodeList = xmlObject.getElementsByTagName("advertising");
		
		NodeList totalCntNode = xmlObject.getElementsByTagName("totalCount");
		
		NodeList nodeAdSeq = xmlObject.getElementsByTagName("adSeq");
		NodeList nodeAdTitle = xmlObject.getElementsByTagName("adTitle");
		NodeList nodeThumb = xmlObject.getElementsByTagName("attachFileThumb");
		NodeList nodeOrigin = xmlObject.getElementsByTagName("attachFileMain");
		NodeList nodeAdPhone = xmlObject.getElementsByTagName("adverPhone");
		NodeList nodeRegDate = xmlObject.getElementsByTagName("regDate");
		
		String totalCnt = totalCntNode.item(0).getFirstChild().getNodeValue();
		resultSet.setTotalCount(Integer.parseInt(totalCnt));
		
		int count = nodeList.getLength();
		
		for (int i = 0; i < count; i++)
		{
			Element elementData = (Element) nodeList.item(i);
			if (elementData == null)
				continue;
			
			CNLottoAdListData dataSet = new CNLottoAdListData();
			
			if(nodeAdSeq.item(i).getFirstChild() != null)
				dataSet.adSeq = Integer.parseInt(nodeAdSeq.item(i).getFirstChild().getNodeValue());
			
			if(nodeAdTitle.item(i).getFirstChild() != null)
				dataSet.adTitle = nodeAdTitle.item(i).getFirstChild().getNodeValue();
			
			if(nodeThumb.item(i).getFirstChild() != null)
				dataSet.adThumb = nodeThumb.item(i).getFirstChild().getNodeValue();
			
			if(nodeOrigin.item(i).getFirstChild() != null)
				dataSet.adOrigin = nodeOrigin.item(i).getFirstChild().getNodeValue();
			
			if(nodeAdPhone.item(i).getFirstChild() != null)
				dataSet.adPhoneNum = nodeAdPhone.item(i).getFirstChild().getNodeValue();
			
			if(nodeRegDate.item(i).getFirstChild() != null)
				dataSet.regDate = nodeRegDate.item(i).getFirstChild().getNodeValue();
			
			resultSet.addDataSet(dataSet);
		}
	}
}
